package random;

import java.util.Random;

/**
 * Created by Robo on 2018/1/20.
 */
public class RandomUtil {
    private static String[] numbers = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};

    private static String randomString(String[] source) {
        int nextInt = new Random().nextInt(source.length);
        return source[nextInt];
    }

    public static String randomString(String[] source, int length) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int nextInt = new Random().nextInt(source.length);
            sb.append(source[nextInt]);
        }
        return sb.toString();
    }
    public static String randomIntStr (int length) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < length; i++) {
            int nextInt = new Random().nextInt(numbers.length);
            sb.append(numbers[nextInt]);
        }
        return sb.toString();
    }
    public static void main(String[] args) {
        System.out.println(randomString(numbers, 9));
    }
}
